package item.defensive;

import java.util.Random;

public class RandomDefensive {
	
	//generates a random enhancement
	
	public static DefensiveEnhancement random(int level) {
		Random r = new Random();
		
		//one of 4 enhancements is generated
		switch(r.nextInt(4)) {
			case 0: 
				return randomShield(level);
			case 1:
				return randomArmor(level);
			case 2:
				return randomHull(level);
			case 3:
				return randomCrew(level);
		}//end of switch statement
		
		return null;
	}//end of method random
	
	//generates a random shield enhancement
	
	private static Shield randomShield(int level) {
		Random r = new Random(); //number generator
		
		//initialize 
		
		int condition = r.nextInt(100);
		int weight = r.nextInt(20) + 15 * level;
		int shield = r.nextInt(50) + 10 * level;
		
		//compute cost
		
		int cost = (condition - weight * 5 + shield * 2) * level;
		
		//shield generated
		
		Shield s = new Shield(cost, condition, level, weight, shield, shield / 10);
		return s;
	}//end of method randomShield
	
	//generates a random armor enhancement
	
	private static Armor randomArmor(int level) {
		Random r = new Random(); //number generator
		
		//initialize 
		
		int condition = r.nextInt(100);
		int weight = r.nextInt(20) + 15 * level;
		int armor = r.nextInt(50) + 10 * level;
		
		//compute cost
		
		int cost = (condition - weight * 5 + armor * 5) * level;
		
		//armor generated
		
		Armor a = new Armor(cost, condition, level, weight, armor);
		return a;
	}//end of method randomArmor
	
	//generates random hull enhancement
	
	private static Hull randomHull(int level) {
		Random r = new Random(); //number generator
		
		//initialize 
		
		int condition = r.nextInt(100);
		int weight = r.nextInt(20) + 15 * level;
		int hull = r.nextInt(50) + 10 * level;
		
		//compute cost
		
		int cost = (condition - weight * 5 + hull * 5) * level;
		
		//hull generated
		
		Hull h = new Hull(cost, condition, level, weight, hull);
		return h;
	}//end of method randomHull
	
	//generates random crew enhancement
	
	private static Crew randomCrew(int level) {
		Random r = new Random(); //number generator
		
		//initialize 
		
		int condition = r.nextInt(100);
		int weight = r.nextInt(20) + 15 * level;
		int crew = r.nextInt(100) + 50 * level;
		
		//compute cost
		
		int cost = (condition - weight * 5 + crew * 2) * level;
		
		//crew generated
		
		Crew c = new Crew(cost, condition, level, weight, crew);
		return c;
		
	}//end of method randomCrew
}//end of class RandomDefensive
